<%@page language="java" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Expires", "0");
%>
<title>网络服务平台</title>
<link rel="stylesheet" type="text/css" href="/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css">
<link href="/js/uploadify/uploadify.css" type="text/css" rel="stylesheet"/>

<script type="text/javascript" src="/js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/js/uploadify/jquery.uploadify.v2.1.4.min.js"></script>


<style type="text/css">
    .td {
        text-align: right;
        background: #E0ECF8;
    }

    TD {
        FONT-SIZE: 13px;
        FONT-FAMILY: arial;
        nowrap: true;
    }

    table {
        BORDER-COLLAPSE: collapse
    }
</style>

<link rel="stylesheet" href="/editor/themes/default/default.css" />
<link rel="stylesheet" href="/editor/plugins/code/prettify.css" />
<script charset="utf-8" src="/editor/kindeditor.js"></script>
<script charset="utf-8" src="/editor/lang/zh_CN.js"></script>
<script>
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#editor1',{
            uploadJson: '/ke/upload.action',
            /*fileManagerJson: '/editor/jsp/file_manager_json.jsp',*/
            fileManagerJson: '/ke/browsePictures.action',
          /*  pagebreakHtml: '<div style="page-break-after: always;"><span style="display: none;">&nbsp;</span></div>',*/
            allowFileManager: 'true'
        });
    });
</script>

<script>
$(function () {
    $("#uploadify").uploadify({
        'uploader':'/js/uploadify/uploadify.swf',
        'script':'/management/news/addThumbnailForNews.action',
        'cancelImg':'/js/uploadify/cancel.png',
        'scriptData':{
            'id':$('#news.id').val()
        },
        'folder':'UploadFile',
        'queueID':'fileQueue',
        'auto':true,
        'fileDataName':'thumbNail',
        'multi':false,
        'onComplete':function (event, ID, fileObj, response, data) {
            var dataObj = eval("(" + response + ")");
            $('#thumbnail').attr("src", '/thumbnail/' + dataObj.name);
            $('#newsBriefImage').val(dataObj.name);
            $('#briefImageVertical').val(dataObj.vertical);
            if (dataObj.vertical) {
                $('#thumbnail').attr("width", '198');
                $('#thumbnail').attr("height", '300');
            } else {
                $('#thumbnail').attr("height", '180');
                $('#thumbnail').attr("width", '300');
            }
        }
    });

    $.extend($.fn.validatebox.defaults.rules, {
        date:{
            validator:function (value, param) {
                var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
                return reg.test(value);
            },
            message:"请输入正确的日期格式，如2011-02-01"
        },
        /* endDate:{
         validator:function(value, param) {
         var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
         if (!(reg.test(value))) {
         return false;
         }
         var endDate = new Date(Date.parse(value.replace(/-/g, "/")));
         var fromDateValue = $("#" + param[0]).datebox("getValue");
         var fromDate = new Date(Date.parse(fromDateValue.replace(/-/g, "/")));
         if (endDate < fromDate) {
         return false;
         }
         return true;
         },
         message:'请输入正确的日期（格式如2011-02-01且不小于起始时间）'
         },*/
        isNull:{
            validator:function (value, param) {
                return !(/[ 　]/g.test(value));
            },
            message:'请输入新闻标题，不能只输入空格'
        }
    });

    var columnIds = $("#columnIds").attr("value");
    if (columnIds) {
        var t = [];
        t = columnIds.split(",");
        $('#columnsCombo').combotree('setValues', t);
    }
    var inIndex = $("#inIndex").attr("value");
    var indexLevel = $("#indexLevel").attr("value");
    $('#newsInIndex').combobox('setValue', inIndex);

    var position = $("#viceTitlePosition").attr("value");
    $('#newsViceTitlePosition').combobox('setValue', position);

    if (0 == indexLevel) {
        indexLevel = 1;
    }

    $('#newsIndexLevel').combobox('setValue', indexLevel);
});

function save() {
    var dskf = $("#columnsCombo").combobox("getValues");
    if (dskf == "") {
        $.messager.alert('警告', '请选择关联栏目!', 'warning');
        return false;
    }

    var reg = /\d+$/;
    var text = $('#viewTimes').attr('value');

    if (!reg.test(text)) {
        alert('点击数必须为非负数！');
        return false;
    }

    if (1 == $('#userRole').attr('value')) {
        var publish = $("#newsPublished").combobox("getValue");
        $('#published').attr('value', publish);
    }
    editor.sync();

    $("#newsForm").form({
        onSubmit:function () {
            $("#newsForm").attr("target", "_self");
            return $(this).form('validate');
        },
        success:function () {
            if('true' == $('#isForDraft').attr('value')){
                window.location.href = "/management/news/newsDraftIndex.action";
            }else if('true' == $('#isFromCollected').attr('value')){
                window.location.href = "/management/news/collectedNewsIndex.action";
            }else{
                window.location.href = "/management/news/newsManagementIndex.action";
            }
        }
    });

    $("#newsForm").submit();
}

function previewNews() {
    $("#newsForm").attr("action", "/management/news/previewNews.action");
    $("#newsForm").attr("target", "_blank");
    $("#newsForm").submit();
}

//取fck内容的长度
function GetMessageLength(str) {
    var oEditor = FCKeditorAPI.GetInstance(str);
    var oDOM = oEditor.EditorDocument;
    var iLength;

    if (document.all)        // If Internet Explorer.
    {
        iLength = oDOM.body.innerText.length;
    }
    else                    // If Gecko.
    {
        var r = oDOM.createRange();
        r.selectNodeContents(oDOM.body);
        iLength = r.toString().length;
    }
    return iLength
}

function setTitleFont() {
    var font = $("#titlefont").attr("value");
    $("#titlecolor_controll").css("font-family", font);
}

function setTitleSize() {
    var size = $("#titlefontsize").attr("value");
    $("#titlecolor_controll").css("font-size", size);
}

function setViceTitleFont() {
    var font = $("#vicetitlefont").attr("value");
    $("#viceTitleColor_controll").css("font-family", font);
}

function addKeyWords(node) {
    $("#keywords").attr("value", node.text);
}

function chooseVideo() {
    $('#chooseVideoDialog').window('open');
    initVideoGrid();
}

function initVideoGrid() {
    $('#videoGrid').datagrid({
        title:'视频列表',
        iconCls:'icon-save',
        width:"100%",
        height:380,
        width:820,
        nowrap:false,
        striped:true,
        collapsible:true,
        url:'/management/video/fetchVideos.action',
        queryParams:{},
        remoteSort:false,
        idField:'id',
        frozenColumns:[
            [
                {field:'ck', checkbox:true},
                {"width":260, "field":"name", "title":"标题",
                    formatter:function (value, rowData, rowIndex) {
                        return '<a target="_blank" href="/management/video/videoPreview.action?id=' + rowData.id + '">' + value + '</a>';
                    }
                }
            ]
        ],
        columns:[
            [
                {"width":240, "field":"location", "title":"位置"},
                {"width":140, "field":"createDateTime", "title":"发布日期"},
                {"width":80, "field":"id", "title":"操作",
                    formatter:function (value, rowData, rowIndex) {
                        return '<a onclick="deleteVideo(\'' + value + '\');" href="#">删除</a>';
                    }
                }
            ]
        ],
        pagination:true,
        rownumbers:true
    });

    var p = $('#videoGrid').datagrid('getPager');
    if (p) {
        $(p).pagination({
            onBeforeRefresh:function () {
                //	alert('before refresh');
            }
        });
    }
}

function deleteVideo() {
    $('#videoId').val("");
    $('#videoNameSpan').html("");
    $('#videoLocationSpan').html("");
}

function closeVideoDialog() {
    var node = $('#videoGrid').datagrid('getSelected');
    var rows = $('#videoGrid').datagrid('getSelections');

    if (rows.length > 1) {
        $.messager.alert('警告', '请选择一条记录!', 'warning');
        return;
    }

    if (rows.length == 1) {
        $('#videoId').val(node.id);
        $('#videoNameSpan').html("<a  target='_blank' href='/management/video/previewVideo.action?id=" + node.id + "' >" + node.name + "</a>");
        $('#videoLocationSpan').html(node.location);
    }

    $('#chooseVideoDialog').window('close');
}

function queryVideo() {
    var videoName = $("#videoName").val();
    var queryParams = $('#videoGrid').datagrid('options').queryParams;
    queryParams.videoName = videoName;
    $('#videoGrid').datagrid('options').queryParams = queryParams;
    $("#videoGrid").datagrid('reload');
}

function makeDefaultThumbnail() {
    $('#thumbnail').attr("src", '/thumbnail/fengsung_logo_01.jpg');
    $('#newsBriefImage').val('fengsung_logo_01.jpg');
    $('#briefImageVertical').val('false');
    $('#thumbnail').attr("height", '180');
    $('#thumbnail').attr("width", '300');
}

</script>
</head>

<body class="easyui-layout" onKeyDown="if(window.event.keyCode==8)window.event.returnValue=false">
<s:if test="null == #session._login_user_">
    <script type="text/javascript">
        top.location.href = '/admin';
    </script>
</s:if>
<div region="center" style="height:900px;padding:10px;background:#efefef;">
<div id="news-center" class="easyui-tabs" fit="true" border="false">
<div id="p" title="编辑新闻" style="height:1100px;padding:20px;">
    <form id="newsForm" action="/management/news/newsSaveOrUpdate.action" method="post"
          enctype="multipart/form-data">
        <table id="subtitle" border="1" width="100%">
            <tr>
                <td><label>标题</label></td>
                <td>
                    <input name="news.title" id="titlecolor_controll" class="easyui-validatebox" size=50
                           value="${news.title}"
                           required="true">
                </td>
            </tr>
            <tr>
                <td><label>首页标题</label></td>
                <td>
                    <input name="news.indexTitle" class="easyui-validatebox" id="newsIndexTitle" size="50"
                           value="${news.indexTitle}">
                </td>
            </tr>
            <tr>
                <td><label>副标题</label></td>
                <td>
                    <input id="viceTitleColor_controll" name="news.viceTitle" class="easyui-validatebox" size=50
                           value="${news.viceTitle}">
                </td>
            </tr>
            <tr>
                <td><label>副标题位置</label></td>
                <td>
                    <select id="newsViceTitlePosition" class="easyui-combobox" name="news.viceTitlePosition"
                            style="width:200px;"
                            required="true">
                        <option value="0">正标题上方</option>
                        <option value="1">正标题下方</option>
                    </select>

                </td>
            </tr>
            <%-- <tr>
               <td><label>新闻SEO数据</label></td>
               <td><input type="text" name="news.metaData" size=50 value="${news.metaData}"></td>
           </tr> --%>
            <tr>
                <td><label>Meta Description缩略</label></td>
                <td>
                    <input name="news.seoTitle" id="seoTitle" size=50 value="${news.seoTitle}">
                </td>
            </tr>
            <tr>
                <td><label>新闻作者</label></td>
                <td>
                    <input name="news.author" id="author" size=50 value="${news.author}">
                    <input type="hidden" name="news.creatorId" id="creatorId" size=50 value="${news.creatorId}">
                </td>
            </tr>
            <tr>
                <td><label>跳转页面</label></td>
                <td>
                    <input name="news.redirect" id="redirect" size=50 value="${news.redirect}">
                </td>
            </tr>
            <tr>
                <td><label>新闻内容</label></td>
                <td><%--<FCK:editor instanceName="default" inputName="news.context" width="100%" height="800"
                                value="${news.context}" toolbarSet="Default"/>--%>
                    <textarea id="editor1" name="news.context" style="width:100%;height:900px;visibility:hidden;">${news.context}</textarea>
                </td>
            </tr>
            <tr>
                <td><label>新闻摘要</label></td>
                <td>
                    <textarea id="introduction" name="news.introduction"
                              style="width:800px;height:100px;"><s:property
                            value="news.introduction" escape="false"/></textarea>
                </td>
            </tr>
            <tr>
                <td><label>缩略图</label></td>
                <td>
                    <input type="hidden" id="newsBriefImage" name="news.briefImage"
                           value="${news.briefImage}"/>
                    <input id="uploadify" name="uploadify" type="file"/>
                    <%-- <a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>--%>
                    <s:if test="false == news.briefImageVertical">
                        <img id="thumbnail" width="300px" height="180px" src="/thumbnail/${news.briefImage}"/>
                    </s:if>
                    <s:else>
                        <img id="thumbnail" width="198px" height="300px" src="/thumbnail/${news.briefImage}"/>
                    </s:else>
                    <input type="button" value="默认缩略图" onclick="makeDefaultThumbnail()"/>
                </td>
            </tr>
            <tr id="keyword">
                <td><label>文章关键词</label></td>
                <td>
                    <input id="keywords" type="text" name="news.keywords" size=50
                           value="${news.keywords}"/><span
                        style="color:#FF0000">关键词之间请以空格隔开，关键词中若有空格，请以美元符号'$'（无引号）代替</span>
                </td>
            </tr>
            <tr>
                <td><label>栏目关联</label></td>
                <td>
                    <select id="columnsCombo" class="easyui-combotree" name="columns"
                            url="/management/columns/fetchColumnsForTree.action"
                            multiple="true" cascadeCheck="false" style="width:300px;"></select>
                </td>
            </tr>
            <tr>
                <td><label>视频</label></td>
                <td>
                    <label>名称：</label><span id="videoNameSpan"><a target="_blank"
                                                                  href="/management/video/previewVideo.action?id=${video.id}">${video.name}</a></span><br/>
                    <label>地址：</label><span id="videoLocationSpan">${video.location}</span><br/>
                    <input type="hidden" id="videoId" name="news.videoId" value="${news.videoId}"/>
                    <a class="easyui-linkbutton" onClick="chooseVideo()">选择</a>
                    <a class="easyui-linkbutton" onClick="deleteVideo()">取消</a>
                </td>
            </tr>
            <tr>
                <td><label>置顶级别</label></td>
                <td>
                    <select id="newsInIndex" class="easyui-combobox" name="news.inIndex" style="width:200px;"
                            required="true">
                        <option value="0">无</option>
                        <option value="1">频道页</option>
                        <option value="2">首页</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><label>推荐级别</label></td>
                <td>
                    <select id="newsIndexLevel" class="easyui-combobox" name="news.indexLevel"
                            style="width:200px;" required="true">
                        <option value="1">推荐1</option>
                        <option value="2">推荐2</option>
                        <option value="3">推荐3</option>
                        <option value="4">推荐4</option>
                        <option value="5">推荐5</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><label>来源</label></td>
                <td>
                    <input id="source" type="text" name="news.source" size=50
                           value="${news.source}"/>
                </td>
            </tr>
            <tr>
                <td><label>来源url</label></td>
                <td>
                    <input id="sourceUrl" type="text" name="news.sourceUrl" size=50
                           value="${news.sourceUrl}"/>
                </td>
            </tr>
            <tr>
                <td><label>是否发布：</label></td>
                <td>
                    <s:if test="1 == #session._user_role_">
                        <select id="newsPublished" class="easyui-combobox" name="newsPublished"
                                style="width:200px;"
                                required="true">
                            <s:if test="news.published">
                                <option value="true">是</option>
                                <option value="false">否</option>
                            </s:if>
                            <s:else>
                                <option value="false">否</option>
                                <option value="true">是</option>
                            </s:else>
                        </select>
                    </s:if>
                    <s:else>
                        <s:if test="news.published">
                            是
                        </s:if>
                        <s:else>
                            否
                        </s:else>
                    </s:else>
                </td>
            </tr>

            <tr>
                <td><label>点击数：</label></td>
                <td><input id="viewTimes" value="${news.viewTimes}" name="news.viewTimes"/>
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2">
                    <a class="easyui-linkbutton" onClick="save()">保存</a>
                    <a class="easyui-linkbutton" onClick="previewNews()">预览</a>
                    <a class="easyui-linkbutton" onClick="javascript:history.back()">取消</a>
                </td>
            </tr>
        </table>

        <input type="hidden" name="news.createDate"
               value="<s:date name="news.createDate" format="yyyy-MM-dd HH:mm:ss" />"/>
        <input type="hidden" name="news.publishDate"
               value="<s:date name="news.publishDate" format="yyyy-MM-dd HH:mm:ss" />"/>
        <input type="hidden" id="oldIsInIndex" value="${news.inIndex}"/>
        <input type="hidden" id="oldHasComments" value="${news.hasComment}"/>
        <input type="hidden" id="news.id" value="${news.id}" name="news.id"/>
        <input type="hidden" id="columnIds" name="columnIds" value="${columnIds}"/>
        <input type="hidden" id="inIndex" name="inIndex" value="${news.inIndex}"/>
        <input type="hidden" id="viceTitlePosition" name="viceTitlePosition" value="${news.viceTitlePosition}"/>
        <input type="hidden" id="indexLevel" name="indexLevel" value="${news.indexLevel}"/>
        <input type="hidden" id="suggest" name="suggest" value="${news.suggest}"/>
        <input type="hidden" id="published" name="news.published" value="${news.published}"/>
        <input type="hidden" id="userRole" name="userRole" value="${_user_role_}"/>
        <input type="hidden" id="isForDraft" name="isForDraft" value="${isForDraft}"/>
        <input type="hidden" id="isFromCollected" name="isFromCollected" value="${isFromCollected}"/>
        <input type="hidden" id="collectedNewsId" name="collectedNewsId" value="${collectedNewsId}"/>
        <input type="hidden" id="briefImageVertical" name="news.briefImageVertical"
               value="${news.briefImageVertical}"/>
    </form>
</div>
</div>
</div>

<div id="chooseVideoDialog" closed="true" modal="true" class="easyui-window" title="选择视频" iconCls="icon-save"
     style="width:880px; height:560px;padding:5px;background: #fafafa;">
    <div class="easyui-layout" fit="true">
        <div region="center" border="false" style="padding:10px;background:#efefef;">
            <div id="videoDiv" class="easyui-panel" title="视频搜索" icon="icon-search"
                 style="height:80px;padding:10px;width:820px;">
                <table>
                    <tr>
                        <td><label>标题:</label></td>
                        <td><input name="videoName" id="videoName"/></td>
                        <td style="width:30px"></td>
                        <td><a class="easyui-linkbutton" onclick="queryVideo()">搜索</a></td>
                    </tr>
                </table>
            </div>
            <div id="p1" class="easyui-panel" style="height:400px;">`
                <table id="videoGrid"></table>
            </div>
        </div>
        <div region="south" border="false" style="text-align:right;height:30px;line-height:30px;margin-top: 5px">
            <a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)"
               onclick="closeVideoDialog()">确定</a>
        </div>
    </div>
</div>

</body>
</html>
